/*
	Written By Pradipna Nepal
	www.pradsprojects.com

	Copyright (C) 2011 Prads Projects
	Please read COPYING.txt included along with this source code for more detail.
	If not included, see http://www.gnu.org/licenses/
*/

#include "libEmuInputs.h"

Inputs::Inputs() {
	controller1.vk[BUTTON_A] = 'Z';
	controller1.vk[BUTTON_B] = 'X';
	controller1.vk[BUTTON_DOWN] = VK_DOWN;
	controller1.vk[BUTTON_LEFT] = VK_LEFT;
	controller1.vk[BUTTON_RIGHT] = VK_RIGHT;
	controller1.vk[BUTTON_SELECT] = VK_SPACE;
	controller1.vk[BUTTON_START] = VK_RETURN;
	controller1.vk[BUTTON_UP] = VK_UP;

	for (int i = 0; i < 8; ++i) controller1.buttons[i] = false;
}

void Inputs::keyDown(WPARAM *wParam) {
	for (int i = 0; i < 8; ++i) {
		if (controller1.vk[i] == *wParam) {
			controller1.buttons[i] = true;
			break;
		}
	}
}

void Inputs::keyUp(WPARAM *wParam) {
	for (int i = 0; i < 8; ++i) {
		if (controller1.vk[i] == *wParam) {
			controller1.buttons[i] = false;
			break;
		}
	}	
}

void Inputs::checkInputs(unsigned char *cMem) {
	cMem[0xFFF0] = 0;
	for (int i = 0; i < 8; ++i) {
		if (controller1.buttons[i]) cMem[0xFFF0] |= 1 << i;
	}
}